﻿using IMES.Common.Domain.GoldIngotModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace GoldIngot.API.Application.Commands.SigningWorkCommand
{
    public class SigningWorkUpdateHandler : IRequestHandler<SigningWorkUpdateCommand, Result>
    {

        private readonly IBaseRepositorys<SigningWork> signingRep;
        private readonly ILogger<SigningWorkUpdateHandler> logger;

        public SigningWorkUpdateHandler(IBaseRepositorys<SigningWork> signingRep, ILogger<SigningWorkUpdateHandler> logger)
        {
            this.signingRep = signingRep;
            this.logger = logger;
        }

        public async Task<Result> Handle(SigningWorkUpdateCommand request, CancellationToken cancellationToken)
        {
            var quest = new Result() { Code = (int)CodeEnum.success };

            var list = signingRep.GetAll().FirstOrDefault(x => x.SigningId == request.SigningId);
            if (list != null)
            {
                list.WorkSheetId = request.WorkSheetId;
                list.SigningNum = request.SigningNum;
                list.ProduceName = request.ProduceName;
                list.ProcessStatus = request.ProcessStatus;
                list.UnitName = request.UnitName;
                list.GoodNum = request.GoodNum;
                list.BadNum = request.BadNum;
                list.DateStart = request.DateStart;
                list.DateEnd = request.DateEnd;
                list.SigningTime = request.SigningTime;
                list.SigningMin = request.SigningMin;
                list.Standard = request.Standard;
                list.Actual = request.Actual;
                list.PricingType = request.PricingType;
                list.WagesPrice = request.WagesPrice;
                list.RewardMoney = request.RewardMoney;
                list.Penalty = request.Penalty;
            }
            quest.Code = signingRep.Update(list);
            return quest;
        }
    }
}
